package com.example.calendar.ui.components

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CalendarMonth
import androidx.compose.material.icons.filled.CalendarViewDay
import androidx.compose.material.icons.filled.CalendarViewWeek
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material.icons.filled.Task
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.example.calendar.ui.Screen

/**
 * Bottom navigation bar for the Calendar app
 */
@Composable
fun CalendarBottomBar(
    navController: NavController,
    currentRoute: String,
    modifier: Modifier = Modifier
) {
    NavigationBar(
        modifier = modifier
    ) {
        NavigationBarItem(
            icon = { Icon(Icons.Default.CalendarMonth, contentDescription = "Month") },
            label = { Text("Month") },
            selected = currentRoute == Screen.Month.route,
            onClick = {
                if (currentRoute != Screen.Month.route) {
                    navController.navigate(Screen.Month.route) {
                        popUpTo(navController.graph.startDestinationId)
                        launchSingleTop = true
                    }
                }
            }
        )
        
        NavigationBarItem(
            icon = { Icon(Icons.Default.CalendarViewWeek, contentDescription = "Week") },
            label = { Text("Week") },
            selected = currentRoute == Screen.Week.route,
            onClick = {
                if (currentRoute != Screen.Week.route) {
                    navController.navigate(Screen.Week.route) {
                        popUpTo(navController.graph.startDestinationId)
                        launchSingleTop = true
                    }
                }
            }
        )
        
        NavigationBarItem(
            icon = { Icon(Icons.Default.CalendarViewDay, contentDescription = "Day") },
            label = { Text("Day") },
            selected = currentRoute == Screen.Day.route,
            onClick = {
                if (currentRoute != Screen.Day.route) {
                    navController.navigate(Screen.Day.route) {
                        popUpTo(navController.graph.startDestinationId)
                        launchSingleTop = true
                    }
                }
            }
        )
        
        NavigationBarItem(
            icon = { Icon(Icons.Default.Task, contentDescription = "Tasks") },
            label = { Text("Tasks") },
            selected = currentRoute == Screen.Tasks.route,
            onClick = {
                if (currentRoute != Screen.Tasks.route) {
                    navController.navigate(Screen.Tasks.route) {
                        popUpTo(navController.graph.startDestinationId)
                        launchSingleTop = true
                    }
                }
            }
        )
        
        NavigationBarItem(
            icon = { Icon(Icons.Default.Settings, contentDescription = "Settings") },
            label = { Text("Settings") },
            selected = currentRoute == Screen.Settings.route,
            onClick = {
                if (currentRoute != Screen.Settings.route) {
                    navController.navigate(Screen.Settings.route) {
                        popUpTo(navController.graph.startDestinationId)
                        launchSingleTop = true
                    }
                }
            }
        )
    }
}

@Preview
@Composable
fun CalendarBottomBarPreview() {
    MaterialTheme {
        CalendarBottomBar(
            navController = rememberNavController(),
            currentRoute = Screen.Month.route
        )
    }
} 